/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).on('click', '.effects-menu li', function() {
    if(selection !== undefined) {
        //effect info
        var speed = new brSpeed(0, 0);
        var accelerator;
        var maxSpeed;
        var startTime = 1;
        var endTime = startTime + 3;
        var zoom = false;
        //set up
        var action = $(this).attr('data-type');
        switch(action){
            case 'bokeh':
                var ax = (parseInt(Math.random() * 1000) - 500) * myCanvas.width / screenWidth;
                var ay = (parseInt(Math.random() * 1000) - 500) * myCanvas.height / screenHeight;
                accelerator = new brAccelerator(ax, ay);
                var vmaxx = parseInt(Math.random() * 15) * myCanvas.width / screenWidth;
                var vmaxy = parseInt(Math.random() * 15) * myCanvas.height / screenHeight;
                maxSpeed = new brSpeed(vmaxx, vmaxy);
                break;
            case 'bounce':
                var ax = (parseInt(Math.random() * 1000) - 500) * myCanvas.width / screenWidth;
                var ay = (parseInt(Math.random() * 1000) - 500) * myCanvas.height / screenHeight;
                accelerator = new brAccelerator(ax, ay);
                var vmaxx = parseInt(Math.random() * 15) * myCanvas.width / screenWidth;
                var vmaxy = parseInt(Math.random() * 15) * myCanvas.height / screenHeight;
                maxSpeed = new brSpeed(vmaxx, vmaxy);
                break;
            case 'float':
                var ax = (parseInt(Math.random() * 1000) - 500) * myCanvas.width / screenWidth;
                var ay = (parseInt(Math.random() * 1000) - 500) * myCanvas.height / screenHeight;
                accelerator = new brAccelerator(ax, ay);
                var vmaxx = parseInt(Math.random() * 15) * myCanvas.width / screenWidth;
                var vmaxy = parseInt(Math.random() * 15) * myCanvas.height / screenHeight;
                maxSpeed = new brSpeed(vmaxx, vmaxy);
                break;
            case 'fadeIn':
                var ax = (parseInt(Math.random() * 1000) - 500) * myCanvas.width / screenWidth;
                var ay = (parseInt(Math.random() * 1000) - 500) * myCanvas.height / screenHeight;
                accelerator = new brAccelerator(ax, ay);
                var vmaxx = parseInt(Math.random() * 15) * myCanvas.width / screenWidth;
                var vmaxy = parseInt(Math.random() * 15) * myCanvas.height / screenHeight;
                maxSpeed = new brSpeed(vmaxx, vmaxy);
                break;
            case 'fadeOut':
                var ax = (parseInt(Math.random() * 1000) - 500) * myCanvas.width / screenWidth;
                var ay = (parseInt(Math.random() * 1000) - 500) * myCanvas.height / screenHeight;
                accelerator = new brAccelerator(ax, ay);
                var vmaxx = parseInt(Math.random() * 15) * myCanvas.width / screenWidth;
                var vmaxy = parseInt(Math.random() * 15) * myCanvas.height / screenHeight;
                maxSpeed = new brSpeed(vmaxx, vmaxy);
                break;
            case 'pulse':
                var ax = (parseInt(Math.random() * 1000) - 500) * myCanvas.width / screenWidth;
                var ay = (parseInt(Math.random() * 1000) - 500) * myCanvas.height / screenHeight;
                accelerator = new brAccelerator(ax, ay);
                var vmaxx = parseInt(Math.random() * 15) * myCanvas.width / screenWidth;
                var vmaxy = parseInt(Math.random() * 15) * myCanvas.height / screenHeight;
                maxSpeed = new brSpeed(vmaxx, vmaxy);
                zoom = true;
                break;
        }
        selection.addEffect(action + 'Effect', accelerator, maxSpeed, speed, accelerator, startTime, endTime, zoom);
        var animation_name = capitaliseFirstLetter(action);
        var li = '<li class="animation">' +
                '<i class="fa fa-star"></i>' +
                '<span class="animate-name" title="' + animation_name + '">' + animation_name + '</span>' +
                '<input class="animate-timer" type="number" min="1" max="100" value="1"/>' +
                '<span>s</span>' +
                '<i class="fa fa-clear"></i>' +
            '</li>';
        $('.animation-list').append(li);
    }
});

$(document).on('click', '.animation-list i.fa-clear', function() {
    selection.removeEffect($('.animation-list li').index($(this).parent()));
    $(this).parent().remove();
});

$(document).on('change', '.animate-timer', function() {
    if(selection !== undefined) {
        var index = $('.animation-list li').index($(this).parent());
        selection.effectsInfo[index].startTime = parseInt($(this).val());
        selection.effectsInfo[index].endTime = parseInt($(this).val()) + 3;
    }
});

/*function addEffect(object, accelerator, maxSpeed, speed, startAccelerator, startTime, endTime) {
    object.addEffect('bokehEffect', accelerator, maxSpeed, speed, startAccelerator, startTime, endTime, false);
}

function addBokehEffect(object, accelerator, maxSpeed, speed, startAccelerator, startTime, endTime) {
    object.addEffect('bokehEffect', accelerator, maxSpeed, speed, startAccelerator, startTime, endTime, false);
}

function addBounceEffect(object, accelerator, maxSpeed, speed, startAccelerator, startTime, endTime) {
    object.addEffect('bounceEffect', accelerator, maxSpeed, speed, startAccelerator, startTime, endTime, false);
}

function addPulseEffect(object, accelerator, maxSpeed, speed, startAccelerator, startTime, endTime) {
    object.addEffect('pulseEffect', accelerator, maxSpeed, speed, startAccelerator, startTime, endTime, true);
}

function addFloatEffect(object, accelerator, maxSpeed, speed, startAccelerator, startTime, endTime) {
    object.addEffect('floatEffect', accelerator, maxSpeed, speed, startAccelerator, startTime, endTime, false);
}

function addFadeInEffect(object, accelerator, maxSpeed, speed, startAccelerator, startTime, endTime) {
    object.addEffect('fadeInEffect', accelerator, maxSpeed, speed, startAccelerator, startTime, endTime, false);
}

function addFadeOutEffect(object, accelerator, maxSpeed, speed, startAccelerator, startTime, endTime) {
    object.addEffect('fadeOutEffect', accelerator, maxSpeed, speed, startAccelerator, startTime, endTime, false);
}*/    
